{$CLEO .cs}
03A4: name_thread 'MOUNTHELI' 
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	// features
	0AF0: 17@ = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "ADVANCED" key "MAXALTITUDE"
	0093: 17@ = integer 17@ to_float

	// if the max altitude is a negative number with floating point, then use the default max altitude value. because max altitude should always be greater than or equal to min altitude(MAXALTITUDE>=MINALTITUDE)
	if
        17@<0.0
    then
        17@=0.0    
    end
else
	// features
	17@ = 60.0 // was 0.0(minimum altitude = maximum altitude), but i changed it into 60.0
end

const
	HK_GOTOMARKER1=15@
	HK_GOTOMARKER2=16@
	
	HK_ABORTMISSION1=15@
	HK_ABORTMISSION2=16@
	
	HK_LAND1=15@
	HK_LAND2=16@
	
	HK_ASCEND1=15@
	HK_ASCEND2=16@
	
	HK_DESCEND1=15@
	HK_DESCEND2=16@
	
	HK_TGLTURMD1=15@
	HK_TGLTURMD2=16@
	
	HK_LANDTOLEADER1=15@
	HK_LANDTOLEADER2=16@
	
	HK_HOVERTARGET1=15@
	HK_HOVERTARGET2=16@
	
	MAXALTITUDE=17@
	
	// function variables
	
	TP			  = 1@
	
    CAMERA_VARNUM = 24
    TX            = 2@
    TY            = 3@
    TZ            = 4@
	                
	LOOPER		  = 5@
	CAMERA_TP	  = 6@
	POINT_TP	  = 7@
    
    POINT_VARNUM  = 8
	NX            = 8@
    NY            = 9@
    NZ            = 10@
	
	N_CAR		  = 11@
	N_PED		  = 12@
	
	AIMED_CAR	  = 18@
	AIMED_PED	  = 19@
	TARGET_CAR	  = 20@
	TARGET_PED	  = 21@
	FOLLOWED_CAR  = 25@
	FOLLOWED_PED  = 26@
	
	CAR_MARK = 22@
	PED_MARK = 23@
	
	AIM_RANGE = 1000.0
	
	// unused 27@ - 30@ and 0@
end

:redefinevar
AIMED_CAR = -1
AIMED_PED = -1
TARGET_CAR = -1
TARGET_PED = -1
FOLLOWED_PED = -1
FOLLOWED_CAR = -1
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: 15@ = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_SHOWPANEL1" 
	0AF0: 16@ = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_SHOWPANEL2"
else
	15@ = 9 // TAB
	16@ = 76 // L
end
:FV_11
0001: wait 0 ms 
077E: get_active_interior_to $Active_Interior 
00D6: if and
0256:   player $PLAYER_CHAR defined 
0038:   $Active_Interior == 0 
80DF:   not actor $PLAYER_ACTOR driving 
0AB0:   key_pressed 15@ // tab
0AB0:   key_pressed 16@ // L
004D: jump_if_false @FV_11 



:activepanel1
01B4: set_player $PLAYER_CHAR can_move 0 
0ADF: add_dynamic_GXT_entry 'CSTMHDR' text "Call Helicopter by aldrinjohnom"
08D4: 12@ = create_panel_with_title 'CSTMHDR' position 32.0 192.0 width 128.0 columns 1 interactive 1 background 1 alignment 1 
08D6: set_panel 12@ column 0 alignment 1 
0ADF: add_dynamic_GXT_entry 'HELMODL' text "Choose Helicopter Model"
0ADF: add_dynamic_GXT_entry 'CMPPNH' text "Companion will Pilot nearby Helicopter"
08DB: set_panel 12@ column 0 header 'HELMODL' data 'CARGOBB' 'RAINDNC' 'LEVIATH' 'SPARROW' 'SEASPAR' 'HUNTER' 'MAVERIC' 'POLMAV' 'SANMAV' 'CMPPNH' 'DUMMY' 'DUMMY'



:activepanel2
0001: wait 0 ms 
00D6: if or
00E1:   player 0 pressed_key 15 
00E1:   player 0 pressed_key 16 
004D: jump_if_false @activepanel2 
00D6: if 
00E1:   player 0 pressed_key 16 
004D: jump_if_false @cancel 
08D7: 13@ = panel 12@ active_row 
08DA: remove_panel 12@ 
01B4: set_player $PLAYER_CHAR can_move 1
0871: init_jump_table 13@ total_jumps 10 default_jump 0 @cancel jumps 0 @CARGOBB 1 @RAINDNC 2 @LEVIATH 3 @SPARROW 4 @SEASPAR 5 @HUNTER 6 @MAVERIC // max of 7 lists
0872: jump_table_jumps 7 @POLMAV 8 @SANMAV 9 @homiepilotchopper -1 @cancel -1 @cancel -1 @cancel -1 @cancel -1 @cancel -1 @cancel // continuation of the table

:cancel
08DA: remove_panel 12@
01B4: set_player $PLAYER_CHAR can_move 1 
0ACE: show_formatted_text_box "You have Cancelled the Selection, Therefore the Helicopter Operation was also Cancelled"
0002: jump @redefinevar 

:homiepilotchopper
00a0: store_actor $PLAYER_ACTOR position_to 1@ 2@ 3@
REPEAT
	wait 0 ms
	8@=-1
	0AE2: 8@ = random_vehicle_near_point 1@ 2@ 3@ in_radius 10.0 find_next 1 pass_wrecked 1
	if and
		056E:  car 8@ defined
		8@<>-1
	then
		0441: 11@ = car 8@ model
		if 0820:  model 11@ heli
		then
			046D: 11@ = actor $PLAYER_ACTOR members_in_group
			if 11@>0
			then
				FOR 14@ = 0 to 7 step 1
					092B: 11@ = group $PLAYER_GROUP member 14@
					if and
						056D: actor 11@ defined
						87D6:  not 11@ == $PLAYER_ACTOR // @ == $ (int)
					then
						break
					end
				end
				if or
					856E: not car 8@ defined 
					856D: not actor 11@ defined
					07D6: 11@ == $PLAYER_ACTOR // @ == $ (int)
				then
					0ACE: show_formatted_text_box "Members does not Exist"
					repeat // avoid spamming keyboard key
						0001: wait 0 ms
						if and
							80E1:  not player 0 pressed_key 15 
							80E1:  not player 0 pressed_key 16 
						then
							break
						end
					until false
					0002: jump @activepanel1 // heli was detected but no companion,terminate the operation
				end
				05CB: AS_actor 11@ enter_car 8@ as_driver 10000000 ms
				0ACE: show_formatted_text_box "Your companion will enter the pilot seat, Have patience. Press the Abort Operation command to terminate the operation."
				REPEAT // examine actor every 1 second if he is inside the chopper, if reached 10 sec and false, then cancel the whole operation
					wait 1000 ms
					if and
						056D:   actor 11@ defined
						056E:   car 8@ defined
					then
						if and
							8118:   not actor 11@ dead
							00DB:   actor 11@ in_car 8@
							04A9:   actor 11@ driving_heli
						then
							04A2: set_heli 8@ fly_to 1@ 2@ 3@ altitude_between 1.0 and 1.0 
							072A: put_actor 11@ into_car 8@ driverseat
							0087: 9@ = MAXALTITUDE // (float)
							9@ *= -1.0
							0087: 14@ = 9@ // (float) // max height
							005B: 14@ += MAXALTITUDE  // (float)
							045A: draw_text_1number 300.0 1.0 GXT 'NUMBER' number 14@  // ~1~ // splashtext indicating amplitude
							0ACE: show_formatted_text_box "The Helicopter is now Ready for Commands and Operations"
							0002: jump @switches  // terminate loop and proceed to operation mode
							break
						else
							if
								0AAB:   file_exists "cleo\Mount to Helicopter.ini"
							then
								0AF0: HK_ABORTMISSION1 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_ABORTMISSION1"
								0AF0: HK_ABORTMISSION2 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_ABORTMISSION2"
							else
								HK_ABORTMISSION1 = 17 // CTRL
								HK_ABORTMISSION2 = 67 // C
							end
							0001: wait 0 ms 
							00D6: if and
								0AB0:    key_pressed HK_ABORTMISSION1 // ctrl
								0AB0:    key_pressed HK_ABORTMISSION2 // C
							then
								05CB: AS_actor 11@ enter_car 8@ as_driver 1 ms // cancel your companion entering the helicopter
								0002: jump @activepanel1 // The user loses patience waiting for his companion to climb the helicopter
								break // make sure that the loop breaks out
							end
						end
					else
						0ACE: show_formatted_text_box "Companion Mount Operation Failed"
						0002: jump @redefinevar
						break // make sure that the loop breaks out
					end
				UNTIL false
				0ACE: show_formatted_text_box "Your Companion has Failed to Enter the Helicopter"
				0002: jump @redefinevar  // after loop, it means that actor failed to go inside the helicopter. terminate loop
			else
				0ACE: show_formatted_text_box "You should have at least one Companion or Gang Member to be the Pilot of an Helicopter"
				repeat
					0001: wait 0 ms
					if and
						80E1:  not player 0 pressed_key 15 
						80E1:  not player 0 pressed_key 16 
					then
						break
					end
				until false
				0002: jump @activepanel1 // heli was detected but no companion,terminate the operation
			end
		end
	end
UNTIL 8@==-1 // until no more car detected on the area
0ACE: show_formatted_text_box "There is no Helicopter nearby"
repeat
	0001: wait 0 ms
	if and
		80E1:  not player 0 pressed_key 15 
		80E1:  not player 0 pressed_key 16 
	then
		break
	end
until false
0002: jump @activepanel1

:CARGOBB
13@=548 // cargobob ID
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: 1@ = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "ADVANCED" key "PILOTID_CARGOBOB"
else
	1@ = 287
end
0002: jump @FV_59 

:RAINDNC
13@=563 // raindance ID
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: 1@ = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "ADVANCED" key "PILOTID_RAINDANCE"
else
	1@ = 287
end
0002: jump @FV_59 

:LEVIATH
13@=417 // leviathan ID
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: 1@ = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "ADVANCED" key "PILOTID_LEVIATHAN"
else
	1@ = 287
end
0002: jump @FV_59 

:SPARROW
13@=469 // sparrow ID
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: 1@ = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "ADVANCED" key "PILOTID_SPARROW"
else
	1@ = 287
end
0002: jump @FV_59 

:SEASPAR
13@=447 // seasparrow ID
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: 1@ = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "ADVANCED" key "PILOTID_SEASPARROW"
else
	1@ = 287
end
0002: jump @FV_59 

:HUNTER
13@=425 // Hunter ID
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: 1@ = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "ADVANCED" key "PILOTID_HUNTER"
else
	1@ = 287
end
0002: jump @FV_59 

:MAVERIC
13@=487 // Maverick ID
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: 1@ = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "ADVANCED" key "PILOTID_MAVERICK"
else
	1@ = 287
end
0002: jump @FV_59 

:POLMAV
13@=497 // Police Maverick ID
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: 1@ = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "ADVANCED" key "PILOTID_POLICEMAVERICK"
else
	1@ = 287
end
0002: jump @FV_59 

:SANMAV
13@=488 // News Chopper ID
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: 1@ = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "ADVANCED" key "PILOTID_NEWSCHOPPER"
else
	1@ = 287
end
0002: jump @FV_59 

:FV_59
0247: load_model 13@ // helicopter
0247: load_model 1@ // pilot
038B: load_requested_models 
0001: wait 0 ms 
00D6: if and
0248:   model 13@ available 
0248:   model 1@ available 
004D: jump_if_false @FV_59

0208: 2@ = random_float_in_ranges -300.0 300.0
0208: 3@ = random_float_in_ranges -300.0 300.0
04C4: store_coords_to 5@ 6@ 7@ from_actor $PLAYER_ACTOR with_offset 2@ 3@ 200.0
00A5: 8@ = create_car 13@ at 5@ 6@ 7@ 
0825: set_helicopter 8@ instant_rotor_start 
0129: 11@ = create_actor_pedtype 8 model 1@ in_car 8@ driverseat
04C4: store_coords_to 5@ 6@ 7@ from_actor $PLAYER_ACTOR with_offset 0.0 10.0 0.0 
04A2: set_heli 8@ fly_to 5@ 6@ 7@ altitude_between 70.0 and 140.0 
0ACE: show_formatted_text_box "The Helicopter is sent to Land at your Location"

gosub @helicopterimmunity

0002: jump @FV_154 

:FV_154
0001: wait 0 ms 
00D6: if 
	80EC:   not actor 11@ sphere 0 near_point 5@ 6@ radius 75.0 1.5
then
	if
		0AAB:   file_exists "cleo\Mount to Helicopter.ini"
	then
		0AF0: HK_ABORTMISSION1 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_ABORTMISSION1"
		0AF0: HK_ABORTMISSION2 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_ABORTMISSION2"
	else
		HK_ABORTMISSION1 = 17 // CTRL
		HK_ABORTMISSION2 = 67 // C
	end
	0001: wait 0 ms 
	00D6: if and
		0AB0:    key_pressed HK_ABORTMISSION1 // ctrl
		0AB0:    key_pressed HK_ABORTMISSION2 // C
	004D: jump_if_false @FV_154 
	0002: jump @abort
end
04BA: set_car 8@ speed_to 0 
0743: heli 8@ fly_to 5@ 6@ 7@ altitude 0 0
0ACE: show_formatted_text_box "The Helicopter has Arrived and Preparing to Land, Wait for it to Successfully Reach the Surface"  
// 00BA: show_text_styled GXT 'FEM_OK' time 1000 style 1  // OK
0002: jump @operationsready 

:operationsready
0001: wait 0 ms 
00D6: if 
056E:   car 8@ defined 
004D: jump_if_false @removeleak 
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: 15@ = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_OPERATIONMODE1"
	0AF0: 16@ = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_OPERATIONMODE2"
else
	15@ = 9 // TAB
	16@ = 76 // L
end
0001: wait 0 ms 
00D6: if and
0AB0:   key_pressed 15@ // TAB
0AB0:   key_pressed 16@ // L
004D: jump_if_false @entrpassngr

if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: 3@ = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "ADVANCED" key "TRAVELSPEED"
	0093: 3@ = integer 3@ to_float
else
	3@ = 0.0 // speed of the helicopter. according to my understanding about vehicle speed, this is the percentage ratio of the default speed, in REAL number format. EG. 1.0 = 100% of default speed while 35.7 = 3570% of default speed....... 0.0 or lower will result default speed on my logic here on this script
end

if
	3@>0.0
then
	00AD: set_car 8@ max_speed_to 3@
end
00AA: store_car 8@ position_to 1@ 2@ 4@
0087: 9@ = MAXALTITUDE // (float)
0013: 9@ *= -1.0 // meaning the minimum amplitude(-MAXALTITUDE)
045A: draw_text_1number 300.0 1.0 GXT 'NUMBER' number 0  // ~1~ // splashtext indicating amplitude
// 02CE: 3@ = ground_z_at 1@ 2@ 4@
020A: set_car 8@ door_status_to 4 // locked
0ACE: show_formatted_text_box "Helicopter's doors are now locked and is now Ready for Operations"
0002: jump @switches


:Gotodestination
// 0 min altitude and 60-MAXALTITUDE max
// if
// 	MAXALTITUDE < 60.0
// then
// 	0007: 14@ = 60.0
// else
// 	0087: 14@ = MAXALTITUDE // (float) 
// end
// 0087: 9@ = MAXALTITUDE // (float) 
// 9@-=60.0
//
9@=60.0 // min amplitude
0087: 14@ = 9@ // (float)
005B: 14@ += MAXALTITUDE  // (float) // max amplitude (9@+MAXALTITUDE)
0AB6: store_target_marker_coords_to 1@ 2@ 3@ // IF and SET 
04A2: set_heli 8@ fly_to 1@ 2@ 9@ altitude_between 9@ and 14@ // after reaching destination, the helicopter will just hover the place
// 0743: heli 8@ fly_to 1@ 2@ 9@ altitude 9@ 14@ // after reaching destination, the helicopter will land
020A: set_car 8@ door_status_to 4 // locked
03F0: enable_text_draw 0
0001: wait 0 ms // this evades any newly created splashtexts from being removed
0092: 10@ = float 14@ to_integer 
045A: draw_text_1number 300.0 1.0 GXT 'NUMBER' number 10@  // ~1~ // splashtext indicating amplitude
0ACE: show_formatted_text_box "Helicopter Moving to Marker"  
097A: play_audio_at 0.0 0.0 0.0 event 1138 

// waits for the user to release the key
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: HK_GOTOMARKER1 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_GOTOMARKER1"
	0AF0: HK_GOTOMARKER2 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_GOTOMARKER2"
else
	HK_GOTOMARKER1 = 17 // CTRL
	HK_GOTOMARKER2 = 76 // L
end
repeat
	0001: wait 0 ms
	if or
		8AB0:   not key_pressed HK_GOTOMARKER1 // CTRL
		8AB0:   not key_pressed HK_GOTOMARKER2 // L
	then
		break
	end
until false
//

0002: jump @switches

:entrpassngr
0001: wait 0 ms
00D6: if and
	056E:   car 8@ defined
	056D:   actor 11@ defined
004D: jump_if_false @removereferences
if and
	80DB:   not actor $PLAYER_ACTOR in_car 8@
	80DF:   not actor $PLAYER_ACTOR driving 
	00E1:   player 0 pressed_key 15 // ~k~~VEHICLE_ENTER_EXIT~
004D: jump_if_false @salvaged1 
0407: store_coords_to 5@ 6@ 7@ from_car 8@ with_offset 0.0 0.0 0.0
01EA: 12@ = car 8@ max_passengers
if and
	00EC:   actor $PLAYER_ACTOR sphere 0 near_point 5@ 6@ radius 10.0 10.0
	12@>0
then

	if and
		0AB0:    key_pressed 17 // ctrl
		12@ >= 2
		0431: car 8@ passenger_seat_free 1
	then
		020A: set_car 8@ door_status_to 1 // unlocked
		05CA: AS_actor $PLAYER_ACTOR enter_car 8@ passenger_seat 1 time 10000
	else
		if and
			0AB0:    key_pressed 16 // shift
			12@ >= 3
			0431: car 8@ passenger_seat_free 2
		then
			020A: set_car 8@ door_status_to 1 // unlocked
			05CA: AS_actor $PLAYER_ACTOR enter_car 8@ passenger_seat 2 time 10000
		else
			if and
				0AB0:    key_pressed 20 // CAPSLOCK
				12@ >= 1
				0431: car 8@ passenger_seat_free 0
			then
				020A: set_car 8@ door_status_to 1 // unlocked
				05CA: AS_actor $PLAYER_ACTOR enter_car 8@ passenger_seat 0 time 10000
			end
		end
	end

end
0002: jump @operationsready

:salvaged1
0001: wait 0 ms
00D6: if and
	056E:   car 8@ defined
	056D:   actor 11@ defined
004D: jump_if_false @removereferences
00D6: if or
	0118:   actor 11@ dead
	02BF:   car 8@ sunk 
	0119:   car 8@ wrecked 
	84A9:   not actor 11@ driving_heli
004D: jump_if_false @abort1
020A: set_car 8@ door_status_to 1 // unlocked
0ACE: show_formatted_text_box "ALERT: We have lost contact to the Helicopter and its Pilot"
02d4: car 8@ turn_off_engine
0001: wait 0 ms
0918: set_car_engine_on 8@ to 0
0001: wait 0 ms
081D: set_car_engine_broken 8@ to 1
0001: wait 0 ms
081D: set_car_engine_broken 8@ to 0
0001: wait 0 ms
0002: jump @removeleak

:abort1
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: HK_ABORTMISSION1 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_ABORTMISSION1"
	0AF0: HK_ABORTMISSION2 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_ABORTMISSION2"
else
	HK_ABORTMISSION1 = 17 // CTRL
	HK_ABORTMISSION2 = 67 // C
end
0001: wait 0 ms 
00D6: if and
0AB0:    key_pressed HK_ABORTMISSION1 // ctrl
0AB0:    key_pressed HK_ABORTMISSION2 // C
004D: jump_if_false @operationsready
0002: jump @abort 

:abort
020A: set_car 8@ door_status_to 1 // unlocked
0ACE: show_formatted_text_box "Aborting Operation. We are Going Home"  
04A2: set_heli 8@ fly_to 0.0 0.0 0.0 altitude_between 0.0 and 200.0
:removeleak
if
	0A32:  actor $PLAYER_ACTOR on_turret_of_car
then
	gosub @unturret 
end
gosub @dettachcar
0001: wait 1000 ms
:removereferences
if
	056E:   car 8@ defined
then
	01C3: remove_references_to_car 8@ 
end
if
	056D:   actor 11@ defined
then
	01C2: remove_references_to_actor 11@ // Like turning an actor into a random pedestrian 
end
// 00A6: destroy_car 8@ 
// 0555: remove_weapon 31 from_actor $PLAYER_ACTOR 
03F0: enable_text_draw 0 
0002: jump @redefinevar 

:switches // switches all commands are found here
0001: wait 0 ms 

00D6: if and
	056E:   car 8@ defined
	056D:   actor 11@ defined
004D: jump_if_false @removereferences
// incase there is a turreted car at helicopter, this is its logic system
if
	056E:   car 31@ defined
then
	if
		8185:  not car 31@ health >= 24@
	then
		0224: set_car 31@ health_to 24@
	end
	if // and
		// 00DB:   actor $PLAYER_ACTOR in_car 31@
		8686:   not car 31@ attached
	then
		0683: attach_car 31@ to_car 8@ with_offset 5@ 6@ 7@ rotation 27@ 28@ 29@
	else
		// // these three variables are dummy vars that is why we need to redefine them
		// 077D: 12@ = car 31@ x_angle
		// 077D: 14@ = car 8@ x_angle
		// 0063: 12@ -= 14@
		// 06BE: 13@ = car 31@ y_angle
		// 06BE: 14@ = car 8@ y_angle
		// 0063: 13@ -= 14@
		// 0174: 14@ = car 31@ Z_angle
		// 0174: 10@ = car 8@ Z_angle
		// 0063: 14@ -= 10@
		// //
		if
			80DB:  not actor $PLAYER_ACTOR in_car 31@
		then
			31@=-1
			08C6: set_actor $PLAYER_ACTOR stay_on_bike 0
		end
	end
end
//

if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: HK_HOVERTARGET1 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_HOVERTARGET1"
	0AF0: HK_HOVERTARGET2 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_HOVERTARGET2"
else
	HK_HOVERTARGET1 = 84 // T
	HK_HOVERTARGET2 = 82 // R
end
0001: wait 0 ms 
00D6: if and
0AB0:    key_pressed HK_HOVERTARGET1 // T
0AB0:    key_pressed HK_HOVERTARGET2 // R
then
	0002: jump @hoverontarget
end
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: HK_LAND1 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_LAND1"
	0AF0: HK_LAND2 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_LAND2"
else
	HK_LAND1 = 75
	HK_LAND2 = 76 // L
end
0001: wait 0 ms 
00D6: if and
0AB0:    key_pressed HK_LAND1 // k
0AB0:    key_pressed HK_LAND2 // L
then
	FOLLOWED_CAR = -1
	FOLLOWED_PED = -1
	0002: jump @finalmission 
end
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: HK_GOTOMARKER1 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_GOTOMARKER1"
	0AF0: HK_GOTOMARKER2 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_GOTOMARKER2"
else
	HK_GOTOMARKER1 = 17 // CTRL
	HK_GOTOMARKER2 = 76 // L
end
0001: wait 0 ms 
00D6: if and
0AB0:    key_pressed HK_GOTOMARKER1 // ctrl
0AB0:    key_pressed HK_GOTOMARKER2 // L
then
	FOLLOWED_CAR = -1
	FOLLOWED_PED = -1
	0002: jump @Gotodestination 
end
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: HK_ABORTMISSION1 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_ABORTMISSION1"
	0AF0: HK_ABORTMISSION2 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_ABORTMISSION2"
else
	HK_ABORTMISSION1 = 17 // CTRL
	HK_ABORTMISSION2 = 67 // C
end
0001: wait 0 ms 
00D6: if and
	056E:   car 8@ defined
	056D:   actor 11@ defined
004D: jump_if_false @removereferences
00D6: if and
0AB0:    key_pressed HK_ABORTMISSION1 // ctrl
0AB0:    key_pressed HK_ABORTMISSION2 // C
then
	0002: jump @abort 
end
if or
	0118:   actor 11@ dead
	02BF:   car 8@ sunk 
	0119:   car 8@ wrecked 
	84A9:   not actor 11@ driving_heli
then
	0ACE: show_formatted_text_box "ALERT: We have lost contact to the Helicopter and its Pilot"
	0087: 14@ = 9@ // (float) 
	005B: 14@ += MAXALTITUDE  // (float)
	if and
		14@>=20.0
		82BF: not car 8@ sunk 
		8119: not car 8@ wrecked
		0118:   actor 11@ dead
	then
		0564: heli 8@ simulate_crash_landing
			:crashchecker
			wait 0 ms
			if
				0AAB:   file_exists "cleo\Mount to Helicopter.ini"
			then
				0AF0: HK_TGLTURMD1 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_TGLTURMD1"
				0AF0: HK_TGLTURMD2 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_TGLTURMD2"
			else
				HK_TGLTURMD1 = 76 // L
				HK_TGLTURMD2 = 84 // T
			end
			0001: wait 0 ms 
			if and
				0AB0:   key_pressed HK_TGLTURMD1 // L
				0AB0:   key_pressed HK_TGLTURMD2 // T
				0A32:  actor $PLAYER_ACTOR on_turret_of_car
			then
				gosub @unturret 
			end
			gosub @dettachcar
			00AA: store_car 8@ position_to 1@ 2@ 3@
			02ce: 4@ = ground_z_at 1@ 2@ 3@
			0063: 3@ -= 4@  // (float)
			03F0: enable_text_draw 0 // disable splashtext
			0001: wait 0 ms // to avoid our new splatext to be erased by the opcode above
			0092: 10@ = float 3@ to_integer 
			045A: draw_text_1number 300.0 1.0 GXT 'NUMBER' number 10@  // ~1~ // splashtext indicating amplitude
			if
				3@<=3.0
			004D: jump_if_false @crashchecker
			
			if
				14@<60.0
			then
				10@=60000.0
				0073: 10@ /= 14@ // (float)
				0092: 10@ = float 10@ to_integer 
				wait 10@ ms
			end
			// if
			// 	14@<60.0
			// then
			// 	0325:  10@ = create_car 8@ fire
			// 	0973:  fire %1d% exists
			// 	0976:  destroy_particle %1d%
			// end
			020b: explode_car 8@
	end
	
	02d4: car 8@ turn_off_engine
	0001: wait 0 ms
	0918: set_car_engine_on 8@ to 0
	0001: wait 0 ms
	081D: set_car_engine_broken 8@ to 1
	0001: wait 0 ms
	081D: set_car_engine_broken 8@ to 0
	0001: wait 0 ms
	0002: jump @removeleak
end
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: HK_ASCEND1 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_ASCEND1"
	0AF0: HK_ASCEND2 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_ASCEND2"
else
	HK_ASCEND1 = 89 // N
	HK_ASCEND2 = 89 // N
end
0001: wait 0 ms 
00D6: if and
	0AB0:   key_pressed HK_ASCEND1 // Y
	0AB0:   key_pressed HK_ASCEND2 // Y
then
	0002: jump @ascendaltitude 
end
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: HK_DESCEND1 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_DESCEND1"
	0AF0: HK_DESCEND2 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_DESCEND2"
else
	HK_DESCEND1 = 76 // L
	HK_DESCEND2 = 76 // L
end
0001: wait 0 ms 
00D6: if  and
	0AB0:   key_pressed HK_DESCEND1 // N
	0AB0:   key_pressed HK_DESCEND2 // N
then
	0002: jump @descendaltitude 
end
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: HK_LANDTOLEADER1 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_LANDTOLEADER1"
	0AF0: HK_LANDTOLEADER2 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_LANDTOLEADER2"
else
	HK_LANDTOLEADER1 = 76 // L
	HK_LANDTOLEADER2 = 77 // M
end
0001: wait 0 ms 
00D6: if  and
	0AB0:   key_pressed HK_LANDTOLEADER1 // L
	0AB0:   key_pressed HK_LANDTOLEADER2 // N
then
	0002: jump @landtoactor 
end
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: HK_TGLTURMD1 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_TGLTURMD1"
	0AF0: HK_TGLTURMD2 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_TGLTURMD2"
else
	HK_TGLTURMD1 = 76 // L
	HK_TGLTURMD2 = 84 // T
end
0001: wait 0 ms 
00D6: if  and
	0AB0:   key_pressed HK_TGLTURMD1 // L
	0AB0:   key_pressed HK_TGLTURMD2 // T
then
	0002: jump @mountposition 
end
00D6: if  and // if user pressed change weapon to previous weapon while in turret-mode
	00E1:   player 0 pressed_key 5 // previous weapon   ~k~~PED_CYCLE_WEAPON_LEFT~/  
	0A32:   actor $PLAYER_ACTOR on_turret_of_car
then
	4@=0 // indicator that loop should cycle to the left
	0002: jump @changeweap
end
00D6: if  and // if user pressed change weapon to next weapon while in turret-mode
	00E1:   player 0 pressed_key 7 // next weapon   ~k~~PED_CYCLE_WEAPON_RIGHT~/ 
	0A32:   actor $PLAYER_ACTOR on_turret_of_car
then
	4@=1 // indicator that loop should cycle to the right
	0002: jump @changeweap
end
if and // if player tries to enter the helicopter
	8A32:   not actor $PLAYER_ACTOR on_turret_of_car
	80DB:   not actor $PLAYER_ACTOR in_car 8@
	80DF:   not actor $PLAYER_ACTOR driving
	00E1:   player 0 pressed_key 15 // ~k~~VEHICLE_ENTER_EXIT~
then
	0407: store_coords_to 12@ 13@ 14@ from_car 8@ with_offset 0.0 0.0 0.0
	01EA: 14@ = car 8@ max_passengers
	if and
		00EC:   actor $PLAYER_ACTOR sphere 0 near_point 12@ 13@ radius 10.0 10.0
		14@>0
	then
		if and
			0AB0:    key_pressed 17 // ctrl
			14@ >= 2
			0431: car 8@ passenger_seat_free 1
		then
			020A: set_car 8@ door_status_to 1 // unlocked
			05CA: AS_actor $PLAYER_ACTOR enter_car 8@ passenger_seat 1 time 10000
		else
			if and
				0AB0:    key_pressed 16 // shift
				14@ >= 3
				0431: car 8@ passenger_seat_free 2
			then
				020A: set_car 8@ door_status_to 1 // unlocked
				05CA: AS_actor $PLAYER_ACTOR enter_car 8@ passenger_seat 2 time 10000
			else
				if and
					0AB0:    key_pressed 20 // CAPSLOCK
					14@ >= 1
					0431: car 8@ passenger_seat_free 0
				then
					020A: set_car 8@ door_status_to 1 // unlocked
					05CA: AS_actor $PLAYER_ACTOR enter_car 8@ passenger_seat 0 time 10000
				end
			end
		end
	end
else
	if
		00DB: actor $PLAYER_ACTOR in_car 8@
	then
		020A: set_car 8@ door_status_to 1 // unlock the door(and get out the chopper if pressed for too long or rapidly tapped)
	end
end

0002: jump @switches

:changeweap
0001: wait 0 ms 

// some hacking, I don't know how this really work
0A96: 13@ = actor $PLAYER_ACTOR struct
000A: 13@ += 0x718 //[byte] Current weapon slot (1 byte)
0A8D: 13@ = read_memory 13@ size 1 virtual_protect 1
//

13@ += 1 // artificial number that when inside the loop, the first index will cancel the - or + 1 on 13@
for 14@ = 1 to 9 step 1 // 1 to 9 means "inspect" fist weapon slot up to throwable weapon slot, you might be wondering why not 3 to 9, I made 1 and 2 an artificial value.
	if 4@==0 // indicates player pressed previous weapon command
	then
		13@ -= 1
	else // indicates player pressed next weapon command
		13@ += 1
	end
	if 13@ > 9 // 9 means up to throwable weapons slot
	then
		13@ = 3 // if above the index of throwable weapons slot, then go back to handgun weapon slot
	else
		if 13@ < 3 // 3 means barrier from handgun weapons slot
		then
			13@ = 9 // if below the index of handgun weapons slot, then go back to throwable weapon slot
		end
	end
	04B8: get_char_weapon_in_slot $PLAYER_ACTOR slot 13@ store_weapon_to 10@ ammo_to 12@ model_to 10@ // 10@ dummy var
	
	if
		12@ > 0 // incase a weapon slot was selected by the logic, this will filter the logic to make sure that it has ammo
	then
		04B8: get_char_weapon_in_slot $PLAYER_ACTOR slot 13@ store_weapon_to 10@ ammo_to 12@ model_to 14@ // 14@ dummy var
		// popup message
		if
			13@ == 1
		then
			0ACE: show_formatted_text_box "Turret Mode: Fist"
		end
		if
			13@ == 2
		then
			0ACE: show_formatted_text_box "Turret Mode: Melee Weapon"
		end
		if
			13@ == 3
		then
			0ACE: show_formatted_text_box "Turret Mode: HandGun"
		end
		if
			13@ == 4
		then
			0ACE: show_formatted_text_box "Turret Mode: ShotGun"
		end
		if
			13@ == 5
		then
			0ACE: show_formatted_text_box "Turret Mode: Sub-MachineGun"
		end
		if
			13@ == 6
		then
			0ACE: show_formatted_text_box "Turret Mode: MachineGun"
		end
		if
			13@ == 7
		then
			0ACE: show_formatted_text_box "Turret Mode: Rifle"
		end
		if
			13@ == 8
		then
			0ACE: show_formatted_text_box "Turret Mode: Heavy-Weapon"
		end
		if
			13@ == 9
		then
			0ACE: show_formatted_text_box "Turret Mode: Throwable-Weapon"
		end
		if
			13@ == 10
		then
			0ACE: show_formatted_text_box "Turret Mode: Special"
		end
		// temporarily remove from turretmode and then change its weapon
		// 0465: remove_actor $PLAYER_ACTOR from_turret_mode
		01B9: set_actor $PLAYER_ACTOR armed_weapon_to 10@
		//
		041A: 13@ = actor $PLAYER_ACTOR weapon 10@ ammo // saves the ammo of the weapon, since going on turret mode increases the ammo by 30000
		// 0002: jump @changeturweap
		0464: put_actor $PLAYER_ACTOR into_turret_on_car 8@ at_car_offset 5@ 6@ 7@ position 2 shooting_angle_limit 360.0 with_weapon 10@ // do not use 5@ 6@ 7@ on other operation. this is considered as static variable
		017B: set_actor $PLAYER_ACTOR weapon 10@ ammo_to 13@ // since the ammo had increased after the turret mode, this reverts back the last ammo of the weapon before the turretmode
		// waits for the user to release the key
		repeat
			0001: wait 0 ms
			if and
				80E1:   not player 0 pressed_key 5 // previous weapon   ~k~~PED_CYCLE_WEAPON_LEFT~/  
				80E1:   not player 0 pressed_key 7 // next weapon   ~k~~PED_CYCLE_WEAPON_RIGHT~/ 
			then
				break
			end
		until false
		//
		0002: jump @switches // if released, then proceed to command operations
		break
	end
end // for
//this will catch incase the for loop fails
04B8: get_char_weapon_in_slot $PLAYER_ACTOR slot 1 store_weapon_to 10@ ammo_to 12@ model_to 14@ // 14@ dummy var
// temporarily remove from turretmode and then change its weapon
// 0465: remove_actor $PLAYER_ACTOR from_turret_mode
01B9: set_actor $PLAYER_ACTOR armed_weapon_to 10@
//

// 0002: jump @changeturweap
0464: put_actor $PLAYER_ACTOR into_turret_on_car 8@ at_car_offset 5@ 6@ 7@ position 2 shooting_angle_limit 360.0 with_weapon 10@ // do not use 5@ 6@ 7@ on other operation. this is considered as static variable
// waits for the user to release the key
repeat
	0001: wait 0 ms
	if and
		80E1:   not player 0 pressed_key 5 // previous weapon   ~k~~PED_CYCLE_WEAPON_LEFT~/  
		80E1:   not player 0 pressed_key 7 // next weapon   ~k~~PED_CYCLE_WEAPON_RIGHT~/ 
	then
		break
	end
until false
//
0002: jump @switches // if released, then proceed to command operations
//

:ascendaltitude
while true
	00D6: if and
		0AB0:   key_pressed HK_ASCEND1 // Y
		0AB0:   key_pressed HK_ASCEND2 // Y
	then
		000B: 9@ += 1.0 // increase the amplitude, this can be negative (up to "- MAXALTITUDE")
		gosub @updateoperation 
		0001: wait 0 ms
	else
		break
	end
end
0002: jump @switches

:descendaltitude
while true
	00D6: if  and
		0AB0:   key_pressed HK_DESCEND1 // N
		0AB0:   key_pressed HK_DESCEND2 // N
	then
		// our amplitude checker that will be used later if the amplitude is above 0.0
		0087: 14@ = 9@ // (float) 
		005B: 14@ += MAXALTITUDE  // (float)
		00D6: if 
		0031:   14@ >= 1.0 // its good to be 61 but i like to have option go down to surface
		004D: jump_if_false @switches
		//
		
		000F: 9@ -= 1.0  // decrease the amplitude, this can be negative (up to "- MAXALTITUDE")
		gosub @updateoperation
		0001: wait 0 ms
	else
		break
	end
end
0002: jump @switches

:updateoperation
// incase 9@ is negative, the helicopter will hover with static amplitude (14@ by 14@):
// eg. 1
// MAXALTITUDE = 36.0 ; this is the max amplitude setting
// 9@ = - 36.0 ; the -MAXALTITUDE (this is the maximum amplitude constant of ours)
// then:
// 14@ = MAXALTITUDE + 9@
// 14@ = 36.0 - 36.0
// total amplitude of zero meaning the chopper will land to surface(0.0 to 0.0 amplitude)
// eg. 2
// MAXALTITUDE = 36.0 ; this is the max amplitude setting
// 9@ = - 15.0 ; the -MAXALTITUDE (this is the maximum amplitude constant of ours)
// then:
// 14@ = MAXALTITUDE + 9@
// 14@ = 36.0 - 15.0
// total amplitude of 16.0 meaning the chopper will hover with amplitude of 16.0 by 16.0
// incase 9@ is positive, the helicopter will hover with static amplitude (9@ to MAXALTITUDE):
// eg.
// MAXALTITUDE = 36.0 ; this is the max amplitude setting
// 9@ = 0.0 ; the -MAXALTITUDE (this is the maximum amplitude constant of ours)
// then:
// 14@ = MAXALTITUDE + 9@
// 14@ = 36.0 - 0.0
// total amplitude of 36.0 meaning the chopper hover with amplitude of 0.0 to 36.0
0087: 14@ = 9@ // (float) // max height
005B: 14@ += MAXALTITUDE  // (float)
if
	FOLLOWED_CAR <> -1
then
	if 
		056E:   car FOLLOWED_CAR defined 
	then
		// if // I commented this because the game crashes when the followed car or ped was not defined anymore
		// 	9@ >= 0.0
		// then
		// 	0780: heli 8@ hover_above actor -1 car FOLLOWED_CAR altitude 9@ 14@
		// else
		// 	0780: heli 8@ hover_above actor -1 car FOLLOWED_CAR altitude 14@ 14@
		// end
		0726: heli 8@ follow_actor -1 follow_car FOLLOWED_CAR radius 14@
		// 0ACE: show_formatted_text_box "Following"
		0002: jump @hoverjumper
	end
end
if
	FOLLOWED_PED <> -1
then
	if
		056D:   actor FOLLOWED_PED defined
	then
		// if // I commented this because the game crashes when the followed car or ped was not defined anymore
		// 	9@ >= 0.0
		// then
		// 	0780: heli 8@ hover_above actor FOLLOWED_PED car -1 altitude 9@ 14@
		// else
		// 	0780: heli 8@ hover_above actor FOLLOWED_PED car -1 altitude 14@ 14@
		// end
		0726: heli 8@ follow_actor FOLLOWED_PED follow_car -1 radius 14@
		0002: jump @hoverjumper
	end
end
if
	9@ >= 0.0
then // fly to location with varying amplitude
	04A2: set_heli 8@ fly_to 1@ 2@ 9@ altitude_between 9@ and 14@ // after reaching destination, the helicopter will just hover the place
else // fly to location with static amplitude, this allows the chopper to land(altitude between 0.0 and 0.0)
	04A2: set_heli 8@ fly_to 1@ 2@ 9@ altitude_between 14@ and 14@ // after reaching destination, the helicopter will just hover the place
end
// 0ACE: show_formatted_text_box "roam"
// 0743: heli 8@ fly_to 1@ 2@ 9@ altitude 9@ 14@ // after reaching destination, the helicopter will land
:hoverjumper
03F0: enable_text_draw 0 
0001: wait 0 ms // this makes newly created splashtext not be affected by removal command above
0092: 10@ = float 14@ to_integer 
045A: draw_text_1number 300.0 1.0 GXT 'NUMBER' number 10@  // ~1~
return

:landtoactor
0001: wait 0 ms 
04C4: store_coords_to 1@ 2@ 3@ from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0 
02CE: 4@ = ground_z_at 1@ 2@ 3@ 
0ACE: show_formatted_text_box "Landing the Helicopter at Your Location,Please Wait"  
// 0780: heli 8@ hover_above actor $PLAYER_ACTOR car -1 altitude 0.0 0.0
// 008B: FOLLOWED_PED = $PLAYER_ACTOR // set cj as the target indicating that cj should be followed
FOLLOWED_PED = -1 // set ped followed to null
FOLLOWED_CAR = -1 // set car followed to null
04A2: set_heli 8@ fly_to 1@ 2@ 4@ altitude_between 0.0 and 0.0 // after reaching destination, the helicopter will just hover the place
// 0743: heli 8@ fly_to 1@ 2@ 4@ altitude 0.0 0.0 // after reaching destination, the helicopter will land
03F0: enable_text_draw 0 // disable splashtext
0087: 9@ = MAXALTITUDE // (float) 
0013: 9@ *= -1.0 // meaning the minimum amplitude(-MAXALTITUDE)
0001: wait 0 ms 
045A: draw_text_1number 300.0 1.0 GXT 'NUMBER' number 0  // ~1~ // splashtext indicating amplitude
097A: play_audio_at 0.0 0.0 0.0 event 1138 

// waits for the user to release the key
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: HK_LANDTOLEADER1 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_LANDTOLEADER1"
	0AF0: HK_LANDTOLEADER2 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_LANDTOLEADER2"
else
	HK_LANDTOLEADER1 = 76 // L
	HK_LANDTOLEADER2 = 77 // M
end
repeat
	0001: wait 0 ms
	if or
		8AB0:   not key_pressed HK_LANDTOLEADER1 // k
		8AB0:   not key_pressed HK_LANDTOLEADER2 // L
	then
		break
	end
until false
//

0002: jump @switches 


:mountposition
0001: wait 0 ms
if and
	80DB:   not actor $PLAYER_ACTOR in_car 8@
	80DF:   not actor $PLAYER_ACTOR driving
	0547:  actor $PLAYER_ACTOR colliding_with_car 8@
	8A32:  not actor $PLAYER_ACTOR on_turret_of_car
then
	
	0470: 10@ = actor $PLAYER_ACTOR current_weapon // it is found at the first line because it allows the weapon to be modified by "next and previos weapon" command
	0ACE: show_formatted_text_box "You are currently in Turret Mode, use this command again to free yourself"
	:changeturweap // this will change the weapon number instead of using the current weapon of actor (stated above) also not show the popup message above
	
	// ~~~~Trigonometric System~~~~
	// we will construct two triangles(has no 90 degrees corner):
	// 1st Triangle is non-right triangle:
	// *Corner1(Helicopter) - Can be defined by global world coordinates
	// *Corner2(Actor) - Can be defined by global world coordinates
	// *Corner3(WORLD ORIGIN[Global Coordinate means 0.0 0.0 0.0 of the world])
	
	// 2nd Triangle is a right triangle(the corner between "X" and "Y" axis is 90 degrees):
	// *Corner1(Helicopter X-Axis)- Since each Object in the world has their OWN 3-Dimensions(Local 3-Dimensions) that is independent on the WORLD 3-Dimension(Global 3-Dimension that is the used by the coodinates computations of opcodes), This X-Axis will be the Right and Left facing of the Helicopter. TAKE NOTE THAT THIS X-AXIS WILL BE THE "OPPOSITE" SIDE
	// *Corner2(Helicopter Y-Axis)- Since each Object in the world has their OWN 3-Dimensions(Local 3-Dimensions) that is independent on the WORLD 3-Dimension(Global 3-Dimension that is the used by the coodinates computations of opcodes), This Y-Axis will be the Front and Back facing of the Helicopter. TAKE NOTE THAT THIS Y-AXIS WILL BE THE "ADJACENT" SIDE
	// *Corner3(Distance between the Actor and the Helicopter in 2D Space) - Which will be the Hypothenuse
	
	// what is our goal and why are we doing this?
	// the opcodes only compute WORLD Coordinates, but not object offsets, our goal is to translate the world coordinate into the helicopter's offset to CJ(ACTOR)
	
	// construct two vectors
 	00a0: store_actor $PLAYER_ACTOR position_to 5@ 6@ 7@ // vector 2
 	00AA: store_car 8@ position_to 12@ 13@ 14@ // vector 1
	//
	
 	0063: 7@ -= 14@  // (float) // difference between height of actor and height of helicopter "with respect to ground". Since "Z"-Axis(Height) is a one dimension perspective that is splitted from "X"-Axis and "Y"-Axis. We can just get the difference between two Z-axis to get the "Z-Offset"... Pretty Easy for the Height
	
	0509: 14@ = distance_between_XY 5@ 6@ and_XY 12@ 13@ // Finding the "Hypothenuse Side" of the "2nd Triangle", this is also the distance between the helicopter and the actor in 2d space using world coordinates.
	0087: 12@ = 14@ // (float) // im just going to save this value on another variable so that I can use 14@ on another operations
	
	// mission:
	// find the angle between the "Corner2" and "Corner3" of the "2nd Triangle"
	0174: 13@ = car 8@ Z_angle // facing angle of the helicopter
	// the z-angle that is computed by opcode 0174 is the z-angle between the WORLD ORIGIN and facing angle of the helicopter, this has excess value present...
	039f: set_car 8@ race_to 5@ 6@ // momentarily make helicopter face actor's world coordinate(5@ as X, 6@ as Y)
	0174: 14@ = car 8@ Z_angle // this is the "Excess" value on our "Z-Angle" at 13@... we need to subract this angle value on the z-angle to find our target angle
 	0175: set_car 8@ Z_angle_to 13@ // Revert to the original face angle of the helicopter
	0063: 13@ -= 14@ // subtract the excess angle value to helicopter's facing angle... The answer will be the angle between "corner2" and "corner3" of the "2nd triagle"... Mission accomplished
	//
	
	// copy the distance between helicopter and actor in 2d space using world coords format
	0087: 5@ = 12@ // (float) // This will Represent "Ho" as Duplicate
	0087: 6@ = 12@ // (float) // This will Represent "Ho" as Duplicate
	//
	
	// ~~~Pythagorean Theorem at 2nd Triangle in 2D Space(neglected the Z-Axis since the z-axis can move alone on itself)~~~
	// We can now find the X-Offset and Y-Offset from Helicopter's Origin going Actor's Origin using our "Artificial 3D Cartesian Plane"(which is the helicopter's local dimension without using the global dimension(WORLD))
	// Variables:
	// Xo = Opposite Side or the Helicopter's X-Axis Offset(Needed to be calculated)
	// Yo = Adjacent Side or the Helicopter's Y-Axis Offset(Needed to be calculated)
	// Ho = Hypothenuse Side or the Distance between the Helicopter and the Actor in 2D space using world coords format
	
	// Formula:
	
	// Sin(13@) = Xo / Ho
	02F6: 14@ = sine 13@
	006B: 5@ *= 14@  // (float)
	//
	
	// Cos(13@) = Yo / Ho
	02F7: 14@ = cosine 13@
	006B: 6@ *= 14@  // (float)
	//
	041A: 13@ = actor $PLAYER_ACTOR weapon 10@ ammo // saves the ammo of the weapon, since going on turret mode increases the ammo by 30000
	// 0002: jump @changeturweap
	0464: put_actor $PLAYER_ACTOR into_turret_on_car 8@ at_car_offset 5@ 6@ 7@ position 2 shooting_angle_limit 360.0 with_weapon 10@ // do not use 5@ 6@ 7@ on other operation. this is considered as static variable
	017B: set_actor $PLAYER_ACTOR weapon 10@ ammo_to 13@ // since the ammo had increased after the turret mode, this reverts back the last ammo of the weapon before the turretmode
else
	if
		0A32:  actor $PLAYER_ACTOR on_turret_of_car
	then
		gosub @unturret
		0ACE: show_formatted_text_box "You can now Move Freely"
	else
		if and
			80DB:  not actor $PLAYER_ACTOR in_car 8@
			00DF:  actor $PLAYER_ACTOR driving
			8A32:  not actor $PLAYER_ACTOR on_turret_of_car
		then
			0811: 31@ = actor $PLAYER_ACTOR used_car
			if and
				056E:   car 31@ defined
				8686:   not car 31@ attached
			then
				if
					09CB:   vehicle 31@ colliding_with_vehicle 8@
				then
					// ~~~~Trigonometric System~~~~
					// we will construct two triangles(has no 90 degrees corner):
					// 1st Triangle is non-right triangle:
					// *Corner1(Helicopter) - Can be defined by global world coordinates
					// *Corner2(Actor) - Can be defined by global world coordinates
					// *Corner3(WORLD ORIGIN[Global Coordinate means 0.0 0.0 0.0 of the world])
					
					// 2nd Triangle is a right triangle(the corner between "X" and "Y" axis is 90 degrees):
					// *Corner1(Helicopter X-Axis)- Since each Object in the world has their OWN 3-Dimensions(Local 3-Dimensions) that is independent on the WORLD 3-Dimension(Global 3-Dimension that is the used by the coodinates computations of opcodes), This X-Axis will be the Right and Left facing of the Helicopter. TAKE NOTE THAT THIS X-AXIS WILL BE THE "OPPOSITE" SIDE
					// *Corner2(Helicopter Y-Axis)- Since each Object in the world has their OWN 3-Dimensions(Local 3-Dimensions) that is independent on the WORLD 3-Dimension(Global 3-Dimension that is the used by the coodinates computations of opcodes), This Y-Axis will be the Front and Back facing of the Helicopter. TAKE NOTE THAT THIS Y-AXIS WILL BE THE "ADJACENT" SIDE
					// *Corner3(Distance between the Actor and the Helicopter in 2D Space) - Which will be the Hypothenuse
					
					// what is our goal and why are we doing this?
					// the opcodes only compute WORLD Coordinates, but not object offsets, our goal is to translate the world coordinate into the helicopter's offset to CJ(ACTOR)
					
					// construct two vectors
					00AA: store_car 31@ position_to 5@ 6@ 7@ // vector 2
					00AA: store_car 8@ position_to 12@ 13@ 14@ // vector 1
					//
					
					0063: 7@ -= 14@  // (float) // difference between height of actor and height of helicopter "with respect to ground". Since "Z"-Axis(Height) is a one dimension perspective that is splitted from "X"-Axis and "Y"-Axis. We can just get the difference between two Z-axis to get the "Z-Offset"... Pretty Easy for the Height
					
					0509: 14@ = distance_between_XY 5@ 6@ and_XY 12@ 13@ // Finding the "Hypothenuse Side" of the "2nd Triangle", this is also the distance between the helicopter and the actor in 2d space using world coordinates.
					0087: 12@ = 14@ // (float) // im just going to save this value on another variable so that I can use 14@ on another operations
					
					// mission:
					// find the angle between the "Corner2" and "Corner3" of the "2nd Triangle"
					0174: 13@ = car 8@ Z_angle // facing angle of the helicopter
					// the z-angle that is computed by opcode 0174 is the z-angle between the WORLD ORIGIN and facing angle of the helicopter, this has excess value present...
					039f: set_car 8@ race_to 5@ 6@ // momentarily make helicopter face actor's world coordinate(5@ as X, 6@ as Y)
					0174: 14@ = car 8@ Z_angle // this is the "Excess" value on our "Z-Angle" at 13@... we need to subract this angle value on the z-angle to find our target angle
					0175: set_car 8@ Z_angle_to 13@ // Revert to the original face angle of the helicopter
					0063: 13@ -= 14@ // subtract the excess angle value to helicopter's facing angle... The answer will be the angle between "corner2" and "corner3" of the "2nd triagle"... Mission accomplished
					//
					
					// copy the distance between helicopter and actor in 2d space using world coords format
					0087: 5@ = 12@ // (float) // This will Represent "Ho" as Duplicate
					0087: 6@ = 12@ // (float) // This will Represent "Ho" as Duplicate
					//
					
					// ~~~Pythagorean Theorem at 2nd Triangle in 2D Space(neglected the Z-Axis since the z-axis can move alone on itself)~~~
					// We can now find the X-Offset and Y-Offset from Helicopter's Origin going Actor's Origin using our "Artificial 3D Cartesian Plane"(which is the helicopter's local dimension without using the global dimension(WORLD))
					// Variables:
					// Xo = Opposite Side or the Helicopter's X-Axis Offset(Needed to be calculated)
					// Yo = Adjacent Side or the Helicopter's Y-Axis Offset(Needed to be calculated)
					// Ho = Hypothenuse Side or the Distance between the Helicopter and the Actor in 2D space using world coords format
					
					// Formula:
					
					// Sin(13@) = Xo / Ho
					02F6: 14@ = sine 13@
					006B: 5@ *= 14@  // (float)
					//
					
					// Cos(13@) = Yo / Ho
					02F7: 14@ = cosine 13@
					006B: 6@ *= 14@  // (float)
					//
					
					// cj's car facing angles
					077D: 27@ = car 31@ x_angle
					077D: 14@ = car 8@ x_angle
					0063: 27@ -= 14@
					06BE: 28@ = car 31@ y_angle
					06BE: 14@ = car 8@ y_angle
					0063: 28@ -= 14@
					0174: 29@ = car 31@ Z_angle
					0174: 14@ = car 8@ Z_angle
					0063: 29@ -= 14@
					//
					
					0683: attach_car 31@ to_car 8@ with_offset 5@ 6@ 7@ rotation 27@ 28@ 29@
					08C6: set_actor $PLAYER_ACTOR stay_on_bike 1
					0ACE: show_formatted_text_box "The Vehicle is now Attached to the Helicopter and will not slip-out"
					0227: 24@ = car 31@ health
					03F5: set_car 31@ apply_damage_rules 0
					// 099A: set_car 31@ collision_detection 0
					gosub @colproofimmunity // make the helicopter collision proof, this avoids the helicopter from being damaged by the car when there is turbulence
				else
					31@=-1
				end
			else
				gosub @dettachcar
				0ACE: show_formatted_text_box "The Vehicle has been detached from the Helicopter"
			end
		end
	end
end

// checks if the player released the following buttons
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: HK_TGLTURMD1 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_TGLTURMD1"
	0AF0: HK_TGLTURMD2 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_TGLTURMD2"
else
	HK_TGLTURMD1 = 76 // L
	HK_TGLTURMD2 = 84 // T
end
repeat
0001: wait 0 ms
	if or
		8AB0:  not key_pressed HK_TGLTURMD1 // L
		8AB0:  not key_pressed HK_TGLTURMD2 // T
	then
		if and
			80E1:   not player 0 pressed_key 5 // previous weapon   ~k~~PED_CYCLE_WEAPON_LEFT~/  
			80E1:   not player 0 pressed_key 7 // next weapon   ~k~~PED_CYCLE_WEAPON_RIGHT~/ 
		then
			break
		end
	end
until false
// if released, then proceed to command operations
// 00BA: show_text_styled GXT 'FEM_OK' time 1000 style 1  // OK
0002: jump @switches

:dettachcar
if
	31@<>-1
then
	if
		056E:   car 31@ defined 
	then
		08C6: set_actor $PLAYER_ACTOR stay_on_bike 0
		0684: detach_car 31@ 0.0 0.0 0.0 collision_detection 1
		03F5: set_car 31@ apply_damage_rules 1
		// 099A: set_car 31@ collision_detection 1
		if
			8185:  not car 31@ health >= 24@
		then
			0224: set_car 31@ health_to 24@
		end
		31@=-1
		gosub @helicopterimmunity // recover back the immunity of the helicopter
	end
end
return



:helicopterimmunity
// truth table here
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: 13@ = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "ADVANCED" key "IMMUNITIES"
else
	13@ = 31 // helicopter is godmode
end
if
	13@==1
then
	02AC: set_car 8@ immunities BP 0 FP 0 EP 0 CP 0 MP 1
end
if
	13@==2
then
	02AC: set_car 8@ immunities BP 0 FP 0 EP 0 CP 1 MP 0
end
if
	13@==3
then
	02AC: set_car 8@ immunities BP 0 FP 0 EP 0 CP 1 MP 1
end


if
	13@==4
then
	02AC: set_car 8@ immunities BP 0 FP 0 EP 1 CP 0 MP 0
end
if
	13@==5
then
	02AC: set_car 8@ immunities BP 0 FP 0 EP 1 CP 0 MP 1
end
if
	13@==6
then
	02AC: set_car 8@ immunities BP 0 FP 0 EP 1 CP 1 MP 0
end
if
	13@==7
then
	02AC: set_car 8@ immunities BP 0 FP 0 EP 1 CP 1 MP 1
end



if
	13@==8
then
	02AC: set_car 8@ immunities BP 0 FP 1 EP 0 CP 0 MP 0
end
if
	13@==9
then
	02AC: set_car 8@ immunities BP 0 FP 1 EP 0 CP 0 MP 1
end
if
	13@==10
then
	02AC: set_car 8@ immunities BP 0 FP 1 EP 0 CP 1 MP 0
end
if
	13@==11
then
	02AC: set_car 8@ immunities BP 0 FP 1 EP 0 CP 1 MP 1
end
if
	13@==12
then
	02AC: set_car 8@ immunities BP 0 FP 1 EP 1 CP 0 MP 0
end
if
	13@==13
then
	02AC: set_car 8@ immunities BP 0 FP 1 EP 1 CP 0 MP 1
end
if
	13@==14
then
	02AC: set_car 8@ immunities BP 0 FP 1 EP 1 CP 1 MP 0
end
if
	13@==15
then
	02AC: set_car 8@ immunities BP 0 FP 1 EP 1 CP 1 MP 1
end



if
	13@==16
then
	02AC: set_car 8@ immunities BP 1 FP 0 EP 0 CP 0 MP 0
end
if
	13@==17
then
	02AC: set_car 8@ immunities BP 1 FP 0 EP 0 CP 0 MP 1
end
if
	13@==18
then
	02AC: set_car 8@ immunities BP 1 FP 0 EP 0 CP 1 MP 0
end
if
	13@==19
then
	02AC: set_car 8@ immunities BP 1 FP 0 EP 0 CP 1 MP 1
end
if
	13@==20
then
	02AC: set_car 8@ immunities BP 1 FP 0 EP 1 CP 0 MP 0
end
if
	13@==21
then
	02AC: set_car 8@ immunities BP 1 FP 0 EP 1 CP 0 MP 1
end
if
	13@==22
then
	02AC: set_car 8@ immunities BP 1 FP 0 EP 1 CP 1 MP 0
end
if
	13@==23
then
	02AC: set_car 8@ immunities BP 1 FP 0 EP 1 CP 1 MP 1
end
if
	13@==24
then
	02AC: set_car 8@ immunities BP 1 FP 1 EP 0 CP 0 MP 0
end
if
	13@==25
then
	02AC: set_car 8@ immunities BP 1 FP 1 EP 0 CP 0 MP 1
end
if
	13@==26
then
	02AC: set_car 8@ immunities BP 1 FP 1 EP 0 CP 1 MP 0
end
if
	13@==27
then
	02AC: set_car 8@ immunities BP 1 FP 1 EP 0 CP 1 MP 1
end
if
	13@==28
then
	02AC: set_car 8@ immunities BP 1 FP 1 EP 1 CP 0 MP 0
end
if
	13@==29
then
	02AC: set_car 8@ immunities BP 1 FP 1 EP 1 CP 0 MP 1
end
if
	13@==30
then
	02AC: set_car 8@ immunities BP 1 FP 1 EP 1 CP 1 MP 0
end
if
	13@>30 // 31 and above
then
	02AC: set_car 8@ immunities BP 1 FP 1 EP 1 CP 1 MP 1
end
//
return

:colproofimmunity
// truth table here
if
    0AAB:   file_exists "cleo\Mount to Helicopter.ini"
then
	0AF0: 13@ = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "ADVANCED" key "IMMUNITIES"
else
	13@ = 31 // helicopter is godmode
end
if
	13@==0
then
	02AC: set_car 8@ immunities BP 0 FP 0 EP 0 CP 1 MP 0
end
if
	13@==1
then
	02AC: set_car 8@ immunities BP 0 FP 0 EP 0 CP 1 MP 1
end
if
	13@==2
then
	02AC: set_car 8@ immunities BP 0 FP 0 EP 0 CP 1 MP 0
end
if
	13@==3
then
	02AC: set_car 8@ immunities BP 0 FP 0 EP 0 CP 1 MP 1
end


if
	13@==4
then
	02AC: set_car 8@ immunities BP 0 FP 0 EP 1 CP 1 MP 0
end
if
	13@==5
then
	02AC: set_car 8@ immunities BP 0 FP 0 EP 1 CP 1 MP 1
end
if
	13@==6
then
	02AC: set_car 8@ immunities BP 0 FP 0 EP 1 CP 1 MP 0
end
if
	13@==7
then
	02AC: set_car 8@ immunities BP 0 FP 0 EP 1 CP 1 MP 1
end



if
	13@==8
then
	02AC: set_car 8@ immunities BP 0 FP 1 EP 0 CP 1 MP 0
end
if
	13@==9
then
	02AC: set_car 8@ immunities BP 0 FP 1 EP 0 CP 1 MP 1
end
if
	13@==10
then
	02AC: set_car 8@ immunities BP 0 FP 1 EP 0 CP 1 MP 0
end
if
	13@==11
then
	02AC: set_car 8@ immunities BP 0 FP 1 EP 0 CP 1 MP 1
end
if
	13@==12
then
	02AC: set_car 8@ immunities BP 0 FP 1 EP 1 CP 1 MP 0
end
if
	13@==13
then
	02AC: set_car 8@ immunities BP 0 FP 1 EP 1 CP 1 MP 1
end
if
	13@==14
then
	02AC: set_car 8@ immunities BP 0 FP 1 EP 1 CP 1 MP 0
end
if
	13@==15
then
	02AC: set_car 8@ immunities BP 0 FP 1 EP 1 CP 1 MP 1
end



if
	13@==16
then
	02AC: set_car 8@ immunities BP 1 FP 0 EP 0 CP 1 MP 0
end
if
	13@==17
then
	02AC: set_car 8@ immunities BP 1 FP 0 EP 0 CP 1 MP 1
end
if
	13@==18
then
	02AC: set_car 8@ immunities BP 1 FP 0 EP 0 CP 1 MP 0
end
if
	13@==19
then
	02AC: set_car 8@ immunities BP 1 FP 0 EP 0 CP 1 MP 1
end
if
	13@==20
then
	02AC: set_car 8@ immunities BP 1 FP 0 EP 1 CP 1 MP 0
end
if
	13@==21
then
	02AC: set_car 8@ immunities BP 1 FP 0 EP 1 CP 1 MP 1
end
if
	13@==22
then
	02AC: set_car 8@ immunities BP 1 FP 0 EP 1 CP 1 MP 0
end
if
	13@==23
then
	02AC: set_car 8@ immunities BP 1 FP 0 EP 1 CP 1 MP 1
end
if
	13@==24
then
	02AC: set_car 8@ immunities BP 1 FP 1 EP 0 CP 1 MP 0
end
if
	13@==25
then
	02AC: set_car 8@ immunities BP 1 FP 1 EP 0 CP 1 MP 1
end
if
	13@==26
then
	02AC: set_car 8@ immunities BP 1 FP 1 EP 0 CP 1 MP 0
end
if
	13@==27
then
	02AC: set_car 8@ immunities BP 1 FP 1 EP 0 CP 1 MP 1
end
if
	13@==28
then
	02AC: set_car 8@ immunities BP 1 FP 1 EP 1 CP 1 MP 0
end
if
	13@==29
then
	02AC: set_car 8@ immunities BP 1 FP 1 EP 1 CP 1 MP 1
end
if
	13@==30
then
	02AC: set_car 8@ immunities BP 1 FP 1 EP 1 CP 1 MP 0
end
if
	13@>30 // 31 and above
then
	02AC: set_car 8@ immunities BP 1 FP 1 EP 1 CP 1 MP 1
end
//
return

:finalmission
0001: wait 0 ms 
020A: set_car 8@ door_status_to 1 // unlocked
if
	0A32:  actor $PLAYER_ACTOR on_turret_of_car
then
	gosub @unturret 
end
gosub @dettachcar
00AA: store_car 8@ position_to 1@ 2@ 3@ 
000B: 3@ += 10.0 
02CE: 4@ = ground_z_at 1@ 2@ 3@ 
0395: clear_area 0 at 1@ 2@ 4@ radius 1.0 
0ACE: show_formatted_text_box "Landing the Helicopter,Please Wait"  
// 04A2: set_heli 8@ fly_to 1@ 2@ 4@ altitude_between 4@ and 4@ // after reaching destination, the helicopter will just hover the place
0743: heli 8@ fly_to 1@ 2@ 4@ altitude 4@ 4@ // after reaching destination, the helicopter will land
000B: 4@ += 5.0
:FV_563
0001: wait 1000 ms 
03F0: enable_text_draw 0 // disable splashtext
0001: wait 0 ms // to avoid our new splatext to be erased by the opcode above
00AA: store_car 8@ position_to 1@ 2@ 3@
0092: 10@ = float 3@ to_integer 
045A: draw_text_1number 300.0 1.0 GXT 'NUMBER' number 10@  // ~1~ // splashtext indicating amplitude
00D6: if 
	8035:   not 4@ >= 3@  // (float)
then
	if
		0AAB:   file_exists "cleo\Mount to Helicopter.ini"
	then
		0AF0: HK_ABORTMISSION1 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_ABORTMISSION1"
		0AF0: HK_ABORTMISSION2 = get_int_from_ini_file "cleo\Mount to Helicopter.ini" section "HOTKEYS" key "AJOM_ABORTMISSION2"
	else
		HK_ABORTMISSION1 = 17 // CTRL
		HK_ABORTMISSION2 = 67 // C
	end
	0001: wait 0 ms 
	00D6: if and
		0AB0:    key_pressed HK_ABORTMISSION1 // ctrl
		0AB0:    key_pressed HK_ABORTMISSION2 // C
		004D: jump_if_false @FV_563 
	0002: jump @abort
end
0ACE: show_formatted_text_box "Landing Complete, Helicopter will take-off after 10 seconds"
0001: wait 10000 ms 
0002: jump @removeleak

:unturret
// this section avoids CJ from losing his weapon when exiting turret mode bug...
0470: 6@ = actor $PLAYER_ACTOR current_weapon
041A: 5@ = actor $PLAYER_ACTOR weapon 6@ ammo
04B8: get_char_weapon_in_slot $PLAYER_ACTOR slot 0 store_weapon_to 10@ ammo_to 12@ model_to 7@
01B9: set_actor $PLAYER_ACTOR armed_weapon_to 10@
0465: remove_actor $PLAYER_ACTOR from_turret_mode

041A: 10@ = actor $PLAYER_ACTOR weapon 6@ ammo
if or
	8491: not actor $PLAYER_ACTOR has_weapon 6@
	10@<=0
then
	01B2: give_actor $PLAYER_ACTOR weapon 6@ ammo 5@ // Load the weapon model before using this
end

01B9: set_actor $PLAYER_ACTOR armed_weapon_to 6@
return



:hoverontarget
if and
	00E1:   player 0 pressed_key 6  // Aim Weapon
	044B:   actor $PLAYER_ACTOR on_foot
then
	0AB1: call_scm_func @GetAimed param_count 1 range AIM_RANGE store_to AIMED_CAR AIMED_PED
	if and
		AIMED_CAR <> -1
		803B:  not AIMED_CAR == FOLLOWED_CAR  // (int)
		803B:  not AIMED_CAR == 8@  // (int)
	then
		if
			056E:   car AIMED_CAR defined 
		then
			if
				075C:   marker CAR_MARK enabled
			then
				0164: disable_marker CAR_MARK
			end
			if
				075C:   marker PED_MARK enabled
			then
				0164: disable_marker PED_MARK
			end
			0085: TARGET_CAR = AIMED_CAR // (int)
			0186: CAR_MARK = create_marker_above_car AIMED_CAR
			0165: set_marker CAR_MARK color_to 4
			AIMED_PED = -1
			TARGET_PED = -1
			FOLLOWED_PED = -1
			0ACE: show_formatted_text_box "Target Car Defined"
			0002: jump @switches 
		end
	end
	if and
		AIMED_PED <> -1
		803B:  not AIMED_PED == FOLLOWED_PED  // (int)
	then
		if
			056D:   actor AIMED_PED defined 
		then
			if
				075C:   marker PED_MARK enabled
			then
				0164: disable_marker PED_MARK
			end
			if
				075C:   marker CAR_MARK enabled
			then
				0164: disable_marker CAR_MARK
			end
			0085: TARGET_PED = AIMED_PED // (int)
			0187: PED_MARK = create_marker_above_actor AIMED_PED
			0165: set_marker PED_MARK color_to 4
			AIMED_CAR = -1
			TARGET_CAR = -1
			FOLLOWED_CAR = -1
			0ACE: show_formatted_text_box "Target Person Defined"
			0002: jump @switches
		end
	end
else
	if or
		00E1:   player 0 pressed_key 16  // sprint
		0449:   actor $PLAYER_ACTOR in_a_car
	then
		if
			056E:   car TARGET_CAR defined 
		then
			0085: FOLLOWED_CAR = TARGET_CAR // (int)
			if
				075C:   marker CAR_MARK enabled
			then
				0164: disable_marker CAR_MARK
				0186: CAR_MARK = create_marker_above_car FOLLOWED_CAR
				0165: set_marker CAR_MARK color_to 0
			end
			0001: wait 0 ms
			gosub @updateoperation
			0ACE: show_formatted_text_box "Helicopter now Following the Target Car"
		else
			if
				056D:   actor TARGET_PED defined
			then
				0085: FOLLOWED_PED = TARGET_PED // (int)
				if
					075C:   marker PED_MARK enabled
				then
					0164: disable_marker PED_MARK
					0187: PED_MARK = create_marker_above_actor FOLLOWED_PED
					0165: set_marker PED_MARK color_to 0
				end
				0001: wait 0 ms
				gosub @updateoperation
				0ACE: show_formatted_text_box "Helicopter now Following the Target Person"
			end
		end
	end
end
0002: jump @switches

:GetAimed
0A9F: TP = current_thread_pointer
0AB1: call_scm_func @getLocalVarOffset 2 thread TP var POINT_VARNUM store_to POINT_TP
0AB1: call_scm_func @getLocalVarOffset 2 thread TP var CAMERA_VARNUM store_to CAMERA_TP
00A0: store_actor $PLAYER_ACTOR position_to TX TY TZ
for LOOPER = 1.0 to 0@ step 1.0
	0AA6: call_method 0x514970 struct 0xB6F028 num_params 6 pop 0 POINT_TP CAMERA_TP TZ TY TX LOOPER
	if
		86BD:   not no_obstacles_between TX TY TZ and NX NY NZ solid 0 car 1 actor 1 object 0 particle 0
	then
		0006: N_CAR = -1
		0006: N_PED = -1
		for 30@ = 2.0 to 10.0 step 2.0
			if
				N_CAR == -1
			then
				0AE2: N_CAR = random_vehicle_near_point NX NY NZ in_radius 30@ find_next 1 pass_wrecked 1
			end
			if
				N_PED == -1
			then
				0AE1: N_PED = random_actor_near_point NX NY NZ in_radius 30@ find_next 1 pass_deads 1
			end
			if or
				N_CAR <> -1
				N_PED <> -1
			then
				break
			end
		end
		break
	else
		if and
			86BD:   not no_obstacles_between TX TY TZ and NX NY NZ solid 1 car 0 actor 0 object 1 particle 0
			0AB0:   key_pressed 86 // V
		then
			for 30@ = 1 to 5 step 1
				04D5: create_corona_at NX NY NZ radius 5.0 type 1 flare 0 RGB 0 0 255
				0001: wait 0 ms
			end
			break
		end
	end
end
0AB2: ret 2 N_CAR N_PED // return point coordinates
//0AB2: ret 3 TX TY TZ // return camera coordinates
//0AB2: ret 6 NX NY NZ TX TY TZ // return point and camera coordinates

:getLocalVarOffset
{ Parameters:   Passed:     0@ - thread pointer     1@ - var number   Result:     1@ - var value Example:   
0AB1: call_scm_func @getLocalVarOffset 2 thread 0@ var 0 store_to 1@ }

if
	0@ <> 0 
then
	1@ *= 0x4  
	0A8E: 2@ = 0@ + 0xDC // mission flag 
	if
		2@ == 1  
	then
		1@ += 0xA48960 // mission locals 
	else
		005A: 1@ += 0@    
		1@ += 0x3C  
	end
else
	1@ = 0 
end
0AB2: ret 1 1@